import random
from utils.DBUtils import DBUtils

if __name__ == '__main__':
    """
    # 创建连接
    db = DBUtils("localhost", "root", "xu20010922", "test")
    """
    """
    # 插入多条数据
    params_insert = [(1, 'zhangsan', '123456', 1), (2, 'lisi', '123456', 1), (3, 'wangwu', '123456', 0)]
    sql = "insert into t_user values(%s,%s, %s,%s)"
    print(db.insert(sql, params_insert))
    """
    """
    # 查询多条数据
    params_select = [1,2,3]
    sql = "select * from t_user where user_id in ("+('%s,'*len(params_select))[:-1]+")"
    print(sql)
    print(db.query(sql, params_select))
    """
    """
    # 更新数据
    params_update = [('zhangsan', 'zhangsan123', 1, 1),('lisi','lisi123',1,2),('wangwu','wangwu123',1,3)]
    sql = "update t_user set user_name=%s, user_password=%s, sex=%s where user_id=%s"
    print(db.update(sql, params_update))
    """
    """
    # 删除数据
    params_delete = [1,2]
    sql = "delete from t_user where user_id = %s"
    print(db.delete(sql, params_delete))
    """
    """
    # 删除db连接
    del db
    """
    """
    # 循环插入10个人的信息
    for i in range(1, 11):
        params_insert = (f'person{i}',random.randint(15,30),random.choice(['男','女']),random.random()*10)
        sql = "insert into person(username,age,sex,high) values(%s,%s, %s,%s)"
        db.insert(sql, params_insert)
    """
